import java.lang.reflect.Field;

import sun.misc.Unsafe;

public class DirectMemoryOOM {

	public static int SPACE_1M = 1024 * 1024;

	public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
		Field unsafeField = Unsafe.class.getDeclaredFields()[0];
		unsafeField.setAccessible(true);
		Unsafe unsafe = (Unsafe) unsafeField.get(null);
		int count = 0;
		while (true) {
			System.out.println(count++);
			unsafe.allocateMemory(SPACE_1M);
		}
	}

}
